//
//  ViewController.m
//  09-省市区
//
//  Created by 韩旭 on 16/7/26.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ViewController.h"
#import "Model.h"
#import "HX_City.h"

#define WIDETH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
#define COLORAUTO [UIColor colorWithRed:(arc4random()%256/255.0) green:(arc4random()%256/255.0) blue:(arc4random()%256/255.0) alpha:1.0]

#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *arrSource;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *arr;
@end

@implementation ViewController

- (NSMutableArray *)arrSource {
    if (!_arrSource) {
        self.arrSource = [NSMutableArray array];
    }
    return _arrSource;
}
- (NSMutableArray *)arr {
    if (!_arr) {
        self.arr = [NSMutableArray array];
    }
    return _arr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"省";
    self.view.backgroundColor = [UIColor redColor];
    self.arrSource = [[Model arrGroup] mutableCopy];
    [self creatPath];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight) style:UITableViewStylePlain];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}
- (void)creatPath {
    for (NSDictionary *dic in _arrSource) {
        Model *model = [Model cityModelDic:dic];
        model.Citys = dic[@"Citys"];
        [self.arr addObject:model];
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:3 reuseIdentifier:ID];
    }
    Model *model = _arr[indexPath.row];
    cell.textLabel.text = model.AProvince;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    HX_City *city = [[HX_City alloc] init];
    Model *model = _arr[indexPath.row];
    city.arrCity = [model.Citys mutableCopy];
    [self.navigationController pushViewController:city animated:YES];
}

@end